import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
    
    const config = loadEnv(mode, './')

    return {
        plugins: [
            vue(),
            Components({
              dts: false, //不自动生成组件类型文件 导入包后就能识别
              // importStyle: false 不自动导入样式，已经在main.ts导入
              resolvers: [VantResolver({ importStyle: true })]
            }),
          ],

        resolve: {
            alias: {
              '@': path.resolve(__dirname, 'src'),
            },
            extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
        },

    }

    transpileDependencies: true,
    lintOnSave: false,
    // define: {
    //     'process.env': {
    //       'VUE_APP_BASE_API':"http://192.168.101.148:8088/pesweb/cloud"
    //     }
    // },
    // devServer: {
    //     host: '0.0.0.0',
    //     https: false,
    //     open: true,
    //     disableHostCheck: true, 
    // },
    // server: {
    //     open:true, //自动浏览
    //     port:8088, //端口号
    //     host:'0.0.0.0'
    // },
    //这里用server,和vue之前配置的有所不同
  server: {
    //方式二:设置多个代理
    proxy: {
      //这个路径为http://192.168.1.182:3000/douyu/wgapi/vod/front/vodrank/getTagVideos
      "/pesweb": {
        //target是代理的目标路径
        target: "http://open.douyucdn.cn",
        changeOrigin: true, //必须要开启跨域
        //pathRewrite重写请求的路径,实际请求的路径没有代理标识douyu,需要把斗鱼重置为空字符串
        rewrite: (path) => path.replace(/\/pesweb/, ""), // 路径重写
      },
    },
  },
})
